<template>
    <div class="login-form">
        <!-- 登录 -->
        <h1>登录</h1>
        <v-text-field v-model="username" label="用户名"></v-text-field>
        <v-text-field v-model="password" label="密码" type="password"></v-text-field>
        <v-btn color="primary" @click="login()">登录</v-btn>
        <v-btn color="primary" text @click="signUp()">注册</v-btn>
    </div>
</template>

<script>
import { defineComponent } from '@vue/composition-api'

export default defineComponent({
    setup() {
        
    },
    data() {
        return {
            username: '',
            password: ''
        }
    },
    methods: {
        signUp(){
            console.log('123')
            this.$router.push({name:'SignUp'})
        },
        login(){
            let post_data = {
                userName: this.username,
                password: this.password
            }
            this.$api.user.SigIn(post_data).then(res=>{
                console.log(res)
                // 存储token信息
                localStorage.setItem('token', res.data.data.token)
                localStorage.setItem('username', this.username)
                this.$router.push({name:'Case'})
            })
        }
    }
})
// export default {
//     methods: {
//         signUp(){
//             console.log('123')
//         }
//     }
// }
</script>

<style scoped>
.login-form {
    width: 500px;
    margin: 0 auto;
    text-align: center;
    margin-top: 10%;
}
</style>